package com.lc.qianrenshiye.adapter;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.lc.qianrenshiye.R;
import com.lc.qianrenshiye.conn.AllowancePost;
import com.lc.qianrenshiye.conn.LoanPost;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2016/12/5.
 */
public class LoanAdapter extends ArrayAdapter<LoanPost.LoanEntity> {

    private Context context;
    private LayoutInflater layoutInflater;

    public LoanAdapter(Context context, List<LoanPost.LoanEntity> lists) {
        super(context, 0, lists);

        layoutInflater = LayoutInflater.from(context);

        this.context = context;

    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        LoanPost.LoanEntity loanEntity = getItem(position);

        ViewHolder viewHolder;

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_allwance_list, null)));

            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }

        if (position == 0) {

            viewHolder.title_space.setVisibility(View.VISIBLE);

        } else {

            viewHolder.title_space.setVisibility(View.GONE);

        }

        if (loanEntity.pay_state.equals("1")) {

            viewHolder.item_allwance_order_num_tv.setTextColor(ContextCompat.getColor(context, R.color.black_text_color));
            viewHolder.item_allwance_order_date_tv.setTextColor(ContextCompat.getColor(context, R.color.black_text_color));
            viewHolder.item_allwance_full_payment_date_tv.setTextColor(ContextCompat.getColor(context, R.color.black_text_color));
            viewHolder.item_allwance_money_tv.setTextColor(ContextCompat.getColor(context, R.color.black_text_color));
            viewHolder.item_allwance_payed_money_tv.setTextColor(ContextCompat.getColor(context, R.color.black_text_color));


        } else {

            viewHolder.item_allwance_order_num_tv.setTextColor(ContextCompat.getColor(context, R.color.text_hint_color));
            viewHolder.item_allwance_order_date_tv.setTextColor(ContextCompat.getColor(context, R.color.text_hint_color));
            viewHolder.item_allwance_full_payment_date_tv.setTextColor(ContextCompat.getColor(context, R.color.text_hint_color));
            viewHolder.item_allwance_money_tv.setTextColor(ContextCompat.getColor(context, R.color.text_hint_color));
            viewHolder.item_allwance_payed_money_tv.setTextColor(ContextCompat.getColor(context, R.color.text_hint_color));


        }

        viewHolder.item_allwance_order_num_tv.setText(loanEntity.ordersn);
        viewHolder.item_allwance_order_date_tv.setText(loanEntity.posttime);
        viewHolder.item_allwance_full_payment_date_tv.setText(loanEntity.pay_time);
        viewHolder.item_allwance_money_tv.setText(loanEntity.payment);
        viewHolder.item_allwance_payed_money_tv.setText(loanEntity.pay_money);

        return convertView;
    }

    class ViewHolder {

        @BoundView(R.id.title_space) private TextView title_space;
        @BoundView(R.id.item_allwance_order_num_tv) private TextView item_allwance_order_num_tv;
        @BoundView(R.id.item_allwance_order_date_tv) private TextView item_allwance_order_date_tv;
        @BoundView(R.id.item_allwance_full_payment_date_tv) private TextView item_allwance_full_payment_date_tv;
        @BoundView(R.id.item_allwance_money_tv) private TextView item_allwance_money_tv;
        @BoundView(R.id.item_allwance_payed_money_tv) private TextView item_allwance_payed_money_tv;

    }

}
